/**
 * Copyright (C) 2013 DaiKit.com - daikit-commons module (admin@daikit.com)
 *
 *         Project home : http://code.daikit.com/commons
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.daikit.commons.shared.utils;

/**
 * A random ID generator with capitalized letters and figures
 * 
 * @author tcaselli
 * @version $Revision$ Last modifier: $Author$ Last commit: $Date$
 */
public abstract class DkIdGenerator
{

	private static String[] s_letters =
	{ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y",
			"Z" };
	private static final int s_defaultIdLength = 16;

	/**
	 * Generate a random String with given length made of capitalized letters and figures
	 * 
	 * @param length
	 *           the length of the random String to be generated
	 * @return the generated random String
	 */
	public static String generateRandomId(final int length)
	{
		String id = "";
		String toConcatenate;
		for (int i = 0; i < length; i++)
		{
			if (Math.random() > 0.6)
			{
				toConcatenate = s_letters[(int) Math.floor(Math.random() * 25.99)];
			}
			else
			{
				toConcatenate = String.valueOf((int) Math.floor(Math.random() * 9.99));
			}
			id = id.concat(toConcatenate);
		}
		return id;
	}

	/**
	 * Wrapper to {@link #generateRandomId(int)} with a length of 16
	 * 
	 * @return the generated random String
	 */
	public static String generateRandomId()
	{
		return generateRandomId(s_defaultIdLength);
	}
}
